# seq language lexer+parser
# see t.seq test
%prefix "seq"

%source{
#include <stdio.h>
int nlines= 1;

#if 1
static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
#define PCC_DEBUG(event, rule, level, pos, buffer, length) \
    fprintf(stdout, "%*s%s %s @%d [%.*s]\n", level * 2, "", dbg_str[event], rule, pos, length, buffer)
    /* NOTE: To guarantee the output order, stderr, which can lead a race condition with stdout, is not used. */
fflush(stdout);
#endif

}


list <- '[' _ some_digits* _ ']' _

some_digits <- id list2 / pair

list2 <- '[' _ some_digits* _ ']' _

pair <- (id digit)

digit <- ([0-9]+ _)

id	<- < [a-zA-Z_]+[a-zA-Z_0-9]* > _	{ printf("ID=%s\n",$0); }


_	<-		(space / comment)*
space	<-	(' ' / '\t' / endofline)
comment	<-	'#' (!endofline .)*
endofline	<-	( '\r\n' / '\n' / '\r' / '\n\r' )		{ nlines++; }

%%

int main() {
    seq_context_t *ctx = seq_create(NULL);
    while (seq_parse(ctx, NULL)){;}
    seq_destroy(ctx);
    return 0;
}
